package com.bayern.muchen.more_test.ordertest;

import com.bayern.muchen.more_test.ordertest.pojo.OrderEntity;
import com.bayern.muchen.more_test.ordertest.pojo.OrderRespVo;
import com.bayern.muchen.more_test.ordertest.pojo.OrderVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author QIUYANG
 * @title: OrderTest
 * @description: TODO
 * @date 2022/1/1414:35
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    OrderService orderService;

    @RequestMapping("/send")
    public String sendToken(){
        String token = UUID.randomUUID().toString().replace("-", "");
        redisTemplate.opsForValue().set("order:token:"+"qiuyang",token,5, TimeUnit.MINUTES);
        return "ok";
    }

    @RequestMapping("/submit")
    public OrderRespVo gettoken(@RequestBody OrderVo orderVo){
        OrderRespVo respVo = orderService.submitOrder(orderVo);
        return respVo;
    }

    @RequestMapping("/sss")
    public String send(){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderId(UUID.randomUUID().toString().replace("-", ""));
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "ok";
    }




}
